package BookStore.dao;

import BookStore.model.Book;
import BookStore.util.BDbUtil;
import BookStore.view.A_BOOK;

import javax.swing.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;


public class BookDao {
    private Book book;

    public BookDao(Book temp) {

        this.book = temp;
    }
    public void register_3() throws Exception {
        Connection con_3 = BDbUtil.getCon_3();
        String sql7= "select * from BOOK where id = '" + book.getBookId() + "' ";
        PreparedStatement ps = con_3.prepareStatement(sql7);
        ResultSet result_3 = ps.executeQuery();
        if (result_3.next()) {
            JOptionPane.showMessageDialog(null,"该书籍已存在");
        } else{
            String sql8 = "insert into BOOK (id,name,aulthor,price,kind,press) values ('" + book.getBookId() + "','" + book.getBookName() + "','" + book.getBookAulthor() + "','" +
                    book.getBookPrice()+ "','" + book.getBookKind() + "','" + book.getBookPress() + "')";
            ps = con_3.prepareStatement(sql8);
            int count = ps.executeUpdate();
            JOptionPane.showMessageDialog(null,"书籍添加成功");
            new A_BOOK().setVisible(true);
        }
        con_3.close();
        ps.close();
    }

    public void delete() throws Exception {
        Connection con_3_1 = BDbUtil.getCon_3_1();
    }
}
